package com.wsoft.hr.pm.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.hr.pm.entity.HrPmMemberTemplateEntity;
import com.wsoft.hr.pm.query.activity.member.template.MemberTemplateListQuery;
import com.wsoft.hr.pm.query.activity.member.template.MemberTemplateSaveQuery;
import com.wsoft.hr.pm.query.activity.member.template.MemberTemplateStateQuery;
import com.wsoft.hr.pm.query.activity.member.template.PersonListQuery;
import com.wsoft.hr.pm.query.activity.member.template.target.his.MemberTemplateSaveBatchQuery;
import com.wsoft.hr.pm.service.IHrPmMemberTemplateService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 人员考核活动表 前端控制器
 * @author zhanggukai
 * @since 2025年02月28日 09:21:31
 */
@RestController
@Tag(name = "人员考核活动")
@RequestMapping("/hr/pm/member/template")
public class HrPmMemberTemplateController {

    @Resource
    private IHrPmMemberTemplateService memberTemplateService;
    @Operation(summary = "人员考核活动", description = "人员考核活动")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid MemberTemplateSaveBatchQuery query) {
         memberTemplateService.saveBatchMemTemplate(query);
         return ResponseResult.success("[sys.msg.success]");
    }

    @Operation(summary = "删除人员考核活动", description = "删除人员考核活动")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = memberTemplateService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "人员考核活动分页", description = "人员考核活动分页")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody MemberTemplateListQuery query) {
        PageInfo<HrPmMemberTemplateEntity> page = memberTemplateService.listMemberTemplate(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }

    @Operation(summary = "人员考核模版详情", description = "人员考核模版详情")
    @GetMapping("/getMemberTemplateDetail")
    public ResponseResult getMemberTemplateDetail(@RequestParam("id") Long id) {
        return ResponseResult.success(memberTemplateService.getMemberTemplateDetail(id));
    }

    @Operation(summary = "人员考核模版评分详情", description = "人员考核模版评分详情")
    @GetMapping("/getMemberTemplateScoreDetail")
    public ResponseResult getMemberTemplateScoreDetail(@RequestParam("id") Long id) {
        return ResponseResult.success(memberTemplateService.getMemberTemplateScoreDetail(id));
    }

    @Operation(summary = "人员考核活动详情", description = "人员考核活动详情")
    @GetMapping("/getDetailTop")
    public ResponseResult getDetailTop(@RequestParam("id") Long id) {
        return ResponseResult.success(memberTemplateService.getDetailTop(id));
    }

    @Operation(summary = "我的模版分页列表", description = "我的模版分页列表")
    @PostMapping("/pagePersonMemberTemplate")
    public ResponseResult pagePersonMemberTemplate(@RequestBody PersonListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(memberTemplateService.pagePersonMemberTemplate(query)));
    }

    @Operation(summary = "我参与的考评页列表", description = "我参与的考评分页列表")
    @PostMapping("/pageParticipateMemberTemplate")
    public ResponseResult pageParticipateMemberTemplate(@RequestBody PersonListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(memberTemplateService.pageParticipateMemberTemplate(query)));
    }

    @Operation(summary = "考评指标分页列表", description = "考评指标分页列表")
    @PostMapping("/pageMemberTarget")
    public ResponseResult pageMemberTarget(@RequestBody MemberTemplateListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(memberTemplateService.pageMemberTarget(query)));
    }

    @Operation(summary = "暂存人员模版", description = "暂存人员模版")
    @PostMapping("/tempSave")
    public ResponseResult tempSave(@RequestBody MemberTemplateSaveQuery query) {
         memberTemplateService.tempSaveMemberTemplate(query);
        return ResponseResult.success(memberTemplateService.getMemberTemplateDetail(query.getId()));
    }
    @Operation(summary = "保存或提交人员模版", description = "保存或提交人员模版")
    @PostMapping("/saveOrSubmit")
    public ResponseResult save(@RequestBody @Valid MemberTemplateSaveQuery query) {
        memberTemplateService.saveMemberTemplate(query);
        return ResponseResult.success(memberTemplateService.getMemberTemplateDetail(query.getId()));
    }

    @Operation(summary = "提交评分工作流", description = "提交评分工作流")
    @GetMapping("/submitScoreStage")
    public ResponseResult submitScoreStage(@RequestParam("id") Long id) {
        memberTemplateService.submitScoreStage(id);
        return ResponseResult.success("[sys.msg.success]");
    }

    @Operation(summary = "修改人员模版状态", description = "修改人员模版状态")
    @PostMapping("/updateState")
    public ResponseResult updateState(@RequestBody @Valid MemberTemplateStateQuery query) {
        boolean b = memberTemplateService.updateState(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
}
